home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / dviselect / str.h < prev    next >
Text File  |  1989-06-15  |  1KB  |  35 lines

  1. /*
  2.  * Copyright (c) 1987 University of Maryland Department of Computer Science.
  3.  * All rights reserved.  Permission to copy for any purpose is hereby granted
  4.  * so long as this copyright notice remains intact.
  5.  */
  6.  
  7. /*
  8.  * Internal strings have both a length and a string area, so that they may
  9.  * contain nulls.
  10.  */
  11. typedef struct string {
  12.     int    s_len;
  13.     char    *s_str;
  14. } String;
  15.  
  16. #define s_eq(s1,s2) ((s1)->s_len == (s2)->s_len && _s_eq(s1, s2))
  17.  
  18. /*
  19.  * Strings are created by appending characters to the current "string pool".
  20.  * Once a string has been completed, it is fixed in place and cannot be
  21.  * changed.  Until the string is complete, characters may be added to, and
  22.  * removed from, the end.
  23.  */
  24. #define PoolExpandSize 1024    /* bytes per ExpandPool */
  25.  
  26. String    PoolString;        /* the current string */
  27. char    *PoolPtr;        /* the current position in the pool */
  28. int    PoolLen;        /* amount of space left in the pool */
  29.  
  30. #define s_addc(c) (--PoolLen >= 0 ? *PoolPtr++ = (c), PoolString.s_len++ \
  31.                   : ExpandPool(c))
  32. #define s_delc()  (PoolLen++, PoolPtr--, PoolString.s_len--)
  33. #define s_kill()  (PoolLen += PoolString.s_len, \
  34.            PoolPtr -= PoolString.s_len, PoolString.s_len = 0)
  35.